package com.tm.biz.tree;

/**
 * 搜索二叉树
 */
public class TreeNode {

    int val;

    //左节点
    TreeNode left;

    //右节点
    TreeNode right;

    public TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }

    public static void main(String[] args) {
        /**
         * 左节点
         */
        TreeNode left2 = new TreeNode(2,null,null);
        TreeNode right2 = new TreeNode(4,null,null);
        TreeNode left1 = new TreeNode(3,left2,right2);

        /**
         * 右节点
         */
        TreeNode right1_left2 = new TreeNode(6,null,null);
        TreeNode right1_right2 = new TreeNode(8,null,null);
        TreeNode right1 = new TreeNode(7,right1_left2,right1_right2);

        TreeNode head = new TreeNode(5,left1,right1);
        System.out.println(head);
        dp(head);


    }


    public static void dp(TreeNode node){
        if(node == null){
            return;
        }
        int val = node.val;
        dp(node.left);
        dp(node.right);
        System.out.println(val);
    }
}
